package gui;

import java.awt.*;
import java.util.LinkedList;

import javax.swing.*;

import rulesControl.MovementApprovers;

/**
 * @author Wojciech Łopata
 *
 */

public class ApproversSelectionPanel extends JPanel
{
	private static final long serialVersionUID = -3202964815213975339L;
	private final MovementApprovers [] approvers;
	private JCheckBox [] boxes;
	
	public ApproversSelectionPanel()
	{
		approvers = MovementApprovers.values();
		boxes = new JCheckBox[approvers.length];
		
		setLayout(new GridLayout(0, 1));
		
		for(int i = 0; i < approvers.length; ++i)
		{	
			boxes[i] = new JCheckBox(approvers[i].toString());
			if(!approvers[i].optional()) boxes[i].setSelected(true);
			else add(boxes[i]);
		}
	}
	
	public MovementApprovers [] getSelectedApprovers()
	{
		LinkedList<MovementApprovers> selectedApprovers = new LinkedList<MovementApprovers>();
		for(int i = 0; i < approvers.length; ++i)
			if(boxes[i].isSelected()) selectedApprovers.add(approvers[i]);
		return selectedApprovers.toArray(new MovementApprovers[selectedApprovers.size()]);
	}
}
